package com.zl.credit.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import lombok.val;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MySendSms {
    public  String sendsms(String PhoneNumbers, String TemplateParam,String TemplateCode) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GJ8LvnLFPnCQAbnGxEV", "fO6o5V3gA3lMl4W4d39xZMqGIC708G");
        IAcsClient client = new DefaultAcsClient(profile);
        //生成随机的验证码
        //String newcode = ((int)(Math.random()*9999)+100)+"";
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("code",TemplateCode);
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");

        request.putQueryParameter("PhoneNumbers", PhoneNumbers);
        request.putQueryParameter("SignName", "SkirtShop");
        request.putQueryParameter("TemplateCode", TemplateParam);
        request.putQueryParameter("TemplateParam", JSONObject.toJSONString(map));
       // request.putQueryParameter("TemplateParam", "{\"code\":\"" + newcode + "\"}");
        CommonResponse response=null;
        try {
             response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return response.getData();
    }
}
